(function($) {
    $.fn.errorStyleItem = function() {
        var oldErrore = this.html();
        var StyledError = '';
        StyledError += "<p><span class=\"ui-icon ui-icon-alert\" style=\"float: left; margin-right: .3em;\">";
        StyledError += "</span><strong>Alert:</strong>";
        StyledError += oldErrore ;
        StyledError += "</p>";
        this.replaceWith(StyledError );
    }
})(jQuery);

(function($) {
    $.fn.errorStyle = function() {
        this.addClass('error ui-state-error ui-corner-all');
        this.children('li').errorStyleItem();
    }
})(jQuery);

(function($) {
    $.fn.ajaxUI = function(param) {
        var ajaxClass = 'ajax';
        if (param && param.animation && param.animation == 'line')
            ajaxClass = 'ajax-line';
        
        var ajaxDiv = $(this).children('div.' + ajaxClass);
        if (ajaxDiv.length) {
            var action = (param && param.action) ? param.action : param;
            if (action == 'stop') {
                this.fadeTo('slow', 1);
                ajaxDiv.fadeOut();
            }
            else {
                this.fadeTo('slow', (param && param.opacity) ? param.opacity : 0);
                ajaxDiv.fadeIn();
            }
            return this;
        }
        var ajaxDiv = $('<div class="' + ajaxClass + '"></div>');
        ajaxDiv.css('width', this.width())
        if (param && param.height>0) {
            ajaxDiv.css('height', param.height);
            this.css('padding-top', param.height);
        }
        else {
            ajaxDiv.css('height', this.height());
        }
        this.fadeTo('slow', (param && param.opacity) ? param.opacity : 0);
        this.prepend(ajaxDiv);
        return this;
    }
})(jQuery);


(function($) {
    $.fn.info = function(param) {
        var body = $('body');
        if (param == 'close') {
            this.fadeOut();
            body.removeClass('ui-widget-overlay');        
            return this;
        }
        else {
            body.addClass('ui-widget-overlay');        
            if (this.hasClass('ui-widget-shadow')) {
                this.fadeIn();
                return this;
            }
        }
        
        if (param && param.width>0)
            this.css('width', param.width);
        if (param && param.height>0)
            this.css('height', param.height);
        
        this.addClass('ui-widget-shadow')
            .addClass('ui-corner-all');
        this.css('position', 'absolute')
            .css('opacity', 1)
            .css('left', Math.round((body.width() - this.width())/2))
            .css('top', Math.round((body.height() - this.height())/2));
        var oldContent = this.html();
        var newContent = '';

        newContent += '<div class="ui-widget ui-widget-content ui-corner-all" style="height:100%; overflow:auto;">';
        newContent += oldContent;
        newContent += '</div>';
        
        this.html(newContent);
        this.fadeIn();
        return this;
    };  
})(jQuery);

var _ = function(key) {if (key) return _.translates.key;}
_.translates={};
_.set = function(key, value) {
    _.translates.key = value;
};
_.set('[ERROR]', 'Error');
_.set('[RESULT]', 'Результат перевірки');

function showError(text) {
    $('<div title="' + _('[ERROR]') + '">' + text + '</div>').dialog();
}


$(function(){
    if (window.init) init(); 
    if (window.initTranslates) 
        initTranslates();})